home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / WIZDOC.ZIP;1 / WIZARD.TXT
Encoding:
Text File  |  1993-01-08  |  15.1 KB  |  372 lines

  1. LIBRARIES
  2.  
  3. Summary:
  4.  
  5. This article describes a Microsoft Access library and discusses some
  6. basics on how to create and debug a library, as well as some things to
  7. watch out for.
  8.  
  9. This article assumes that you are familiar with Access Basic and with
  10. creating Access applications with the programming tools provided with
  11. Access.
  12.  
  13. More Information:
  14.  
  15. Access Basic Library Defined
  16. ----------------------------
  17.  
  18. When you write an Access application, such as the NWIND application
  19. with the package, the application works only within the database in
  20. which it was created. This is satisfactory for many applications that
  21. specifically use the data that resides in the application's database.
  22.  
  23. However, many Microsoft Access developers write generic applications,
  24. programs, and utilities that are designed to work on any user
  25. database. An example of this is Wizards. Wizards are Access Basic
  26. programs that reside in their own database, but are available to the
  27. user in any database the user has open. If this weren't the case, you
  28. could not use a Wizard outside of the database that the Wizard program
  29. and system objects reside in. In order to use a program (such as a
  30. Wizard) so that its code and objects are available to any user
  31. database, you must load the database containing the program and its
  32. objects as a library.
  33.  
  34. To load a database as a library, you must open MSACCESS.INI and add an
  35. entry to the Libraries section. When you open MSACCESS.INI initially,
  36. you will probably see a Libraries section with an entry for the
  37. Wizards library:
  38.  
  39.    [Libraries]
  40.    wizard.mda=ro
  41.  
  42. Note: If there is no Libraries section, add it to the end of the file
  43. and continue. The MSACCESS.INI file can be found in your Windows
  44. directory.
  45.  
  46. The "ro" in the Wizard entry means that the library is read-only. If
  47. you have an application that uses system tables that are to be written
  48. to at any point in your program, you would specify "rw" rather than
  49. "ro". For example, suppose you have an application in a file called
  50. STOCKAPP.MDB that employs the use of system tables that can be
  51. modified. You would add the following entry to use the MDB file as a
  52. library:
  53.  
  54.    [Libraries]
  55.    wizard.mda=ro
  56.    stockapp.mdb=rw
  57.  
  58. Given these library entries, the WIZARD.MDA library will be loaded
  59. read-only, and the STOCKAPP.MDB library will be loaded as read- write.
  60. You can now open an Immediate window in a user database and invoke sub
  61. and function procedures from STOCKAPP.MDB, or open tables, queries,
  62. forms, or reports with DoCmd commands. Even though you can access the
  63. code and the database objects, you cannot see them in the Database
  64. window.
  65.  
  66. When a database is loaded as a library, it cannot be opened as a user
  67. database.
  68.  
  69. Writing and Debugging Access Basic Library Code
  70. -----------------------------------------------
  71.  
  72. When you write an Access Basic application for use as a library, you
  73. are doing little more than writing the application in a user database
  74. with the intention of using it as a library at a later point. Because
  75. of this, a rule of thumb is to make sure the application works
  76. completely before trying to use it as a library.
  77.  
  78. Although this rule of thumb is enough to successfully create many
  79. types of library applications, there are some important pitfalls to
  80. watch for when writing a library application, even if the application
  81. works perfectly as a user database.
  82.  
  83. Debugging an Error in a Library Database
  84. ----------------------------------------
  85.  
  86. If the library database generates an error that only occurs while it
  87. is a library, it can be very difficult to locate. An error might occur
  88. that gives you some idea of the general area of the problem, but there
  89. may be little or no indication of the offending line. Because you
  90. cannot set and use breakpoints and stepping in library applications,
  91. you should design error traps that convey meaningful messages and
  92. indicate the location of the problem.
  93.  
  94. Another debugging tip is to place MsgBox's at milestone areas of the
  95. code so that you always have an idea of which code is being executed.
  96.  
  97.  
  98. CodeDB() Versus CurrentDB()
  99. --------------------------- 
  100.  
  101. Access Basic includes the CodeDB() function for opening library
  102. databases. CodeDB() works identically to CurrentDB() if you are
  103. running the application as a user database. However, if you are
  104. running the application as a library, CodeDB() returns the database
  105. object for the library database from which it was called, while
  106. CurrentBD() returns the database object from the current open user
  107. database. Because of this, it is easy to confuse one for the other,
  108. which results in logical errors that do indicate this is the problem.
  109.  
  110.  
  111. Domain Functions
  112. ----------------
  113.  
  114. Domain functions include a parameter that is used as criteria for
  115. applying the function to a specified set of records. The criteria is
  116. in the form of a SQL WHERE statement and assumes first that any table
  117. in the criteria is located in the user database. This could pose a
  118. problem for your application if you intend to perform a domain
  119. function on a library table that happens to have the same name as a
  120. user table. Of course, this does not happen frequently; but it becomes
  121. very important when you work with Microsoft Access system tables which
  122. will have the same name in both databases. If you are to include a
  123. table within your library, you should  give this table a unique name
  124. that you do not expect a user to duplicate such as "My Library
  125. Table1."
  126.  
  127. Macros in a Library Cannot Be Called from a User Database
  128. ---------------------------------------------------------
  129.  
  130. Of all the objects you can create in a Microsoft Access database,
  131. macros are the only type of object you cannot use in a library
  132. application. The most obvious problem this presents is that forms
  133. require the use of macros in order to have menus. Because of this
  134. limitation, you must make sure to use only Access Basic code for
  135. programming.
  136.  
  137.  
  138. WIZARDS PART 1
  139.  
  140. Summary:
  141.  
  142. This article discusses the Microsoft Access undocumented functions 
  143. CreateForm() and CreateReport().  If you intend to write your own
  144. Forms and/or Reports Wizard, you can use these functions to create a
  145. blank form or report to which you can add controls and otherwise
  146. customize.
  147.  
  148. This article assumes that the reader has read and understands the
  149. Knowledge Base article entitled, "Creating, Debugging, and Using an
  150. Access Library" (Q88175).  This article also assumes you are familiar
  151. with Access Basic and with designing forms and reports.
  152.  
  153. This article applies to Microsoft Access Version 1.0.
  154.  
  155.  
  156. More Information:
  157.  
  158. CreateForm()/CreateReport() is roughly equivalent to choosing 'New 
  159. Form/New Report' from the 'File' menu at the top of the screen.  Upon
  160. executing the function, a new, empty form/report will appear in an
  161. iconized state.
  162.  
  163. Both functions return an object value that you can use for further
  164. manipulation and neither function requires parameters.
  165.  
  166. To use these functions, you must first define a form or report object
  167. variable, then Set the variable to the function name.  An example of
  168. how to do this is shown below:
  169.  
  170.    Dim MyForm As Form
  171.    Set MyForm = CreateForm()
  172.  
  173. After opening the form/report in design mode after executing the
  174. commands above, you can bind the form to a table or query by modifying
  175. the form's/report's RecordSource property as shown below:
  176.  
  177.    MyForm.RecordSource = "Categories"
  178.  
  179. With the form/report available in design mode, you can access and 
  180. change any of the other design-time properties of the form/report.  You 
  181. can also access and change properties of each of the form's/report's 
  182. sections via the Section property.  The Section property is actually an 
  183. array with each array value being a reference to a form's/report's 
  184. section.  For forms, the Section property array is broken down as shown 
  185. below:
  186.  
  187.    Section(0) - Detail Section
  188.    Section(1) - Form Header
  189.    Section(2) - Form Footer
  190.    Section(3) - Page Header
  191.    Section(4) - Page Footer
  192.  
  193. For reports, the section property array is broken down like this:
  194.  
  195.    Section(0) - Detail Section
  196.    Section(1) - Report Header
  197.    Section(2) - Report Footer
  198.    Section(3) - Page Header
  199.    Section(4) - Page Footer
  200.    Section(5) - Group Level 1 Header
  201.    Section(6) - Group Level 1 Footer
  202.    Section(7) - Group Level 2 Header
  203.       ...etc.
  204.  
  205. With this information, you could customize the design of a form/report
  206. section programmatically.  The following example creates a new report,
  207. hides the Page Footer by setting its Visible property to False, sets
  208. the Height of the Detail section, and enables its the KeepTogether 
  209. property:
  210.  
  211.    Dim MyReport As Report
  212.    Set MyReport = CreateReport()
  213.    MyReport.Section(4).Visible = False
  214.    MyReport.Section(0).Height = 1760
  215.    MyReport.Section(0).KeepTogether = True
  216.  
  217.  
  218. WIZARDS PART 2
  219.  
  220.  
  221. Summary:
  222.  
  223. This article discusses the Microsoft Access undocumented functions 
  224. CreateControl() and CreateReportControl().  If you intend to write your 
  225. own Forms and/or Reports Wizard, you can use these functions to create 
  226. controls on a form or report that is available in Design mode.
  227.  
  228. This article assumes that the reader has read and understands the
  229. Knowledge Base articles entitled, "Creating, Debugging, and Using an
  230. Access Library" (Q88175), and "Wizards Part I - CreateForm(), 
  231. CreateReport(), Section Property" (Q?????).  This article also assumes 
  232. you are familiar with Access Basic and with designing forms and 
  233. reports.
  234.  
  235. This article applies to Microsoft Access Version 1.0.
  236.  
  237.  
  238. More Information:
  239.  
  240. CreateControl() and CreateReportControl() can be used to create new
  241. controls for a form/report opened in Design mode.  These functions
  242. require the name of the form/report represented as a string value,
  243. and a numeric code that represents the type of control.  The list of 
  244. control types and their associated numeric codes are shown below:
  245.  
  246.    Label .......... 100
  247.    Box ............ 101
  248.    Line ........... 102
  249.    Picture ........ 103
  250.    Button ......... 104
  251.    Radio Button ... 105
  252.    Check Box ...... 106
  253.    Ole Object ..... 108
  254.    Text Box ....... 109
  255.  
  256. The CreateControl() and CreateReportControl() functions return a
  257. control object value, so you must first define a control variable,
  258. then Set the variable to the function name.  Note the code example
  259. below which creates a form, then adds a button to the form:
  260.  
  261.    Dim MyForm As Form, MyControl As Control
  262.    Set MyForm = CreateForm()
  263.    Set MyControl = CreateControl(MyForm.FormName, 104)
  264.  
  265. After executing the code example above, you can modify the properies
  266. of the new control via the control variable you defined.  For example:
  267.  
  268.    MyControl.Width = 2000
  269.    MyControl.Caption = "&Sum All Records"
  270.  
  271. For controls that are frequently associated with fields in a table or
  272. query, you can modify the ControlSource property to bind the control.
  273. Some controls are created with Height and Width properties set to 0,
  274. so that they are - in effect - not visible.  In addition, controls
  275. appear at the uppermost left-hand corner of the form by default. 
  276. Because of this, you should make it a habit to adjust the size and
  277. position of the control immediately after creating it.  The example
  278. below shows how to create, size, move, and bind a text box.
  279.  
  280.    Set MyControl = CreateControl(MyForm.FormName, 109)
  281.    MyControl.Width = 1500
  282.    MyControl.Height = 200
  283.    MyControl.Top = 440
  284.    MyControl.Left = 200
  285.    MyControl.ControlSource = "[Category ID]"
  286.  
  287. In addition to specifying the form name and type of control, you can
  288. optionally specify the Section in which the control should be created.
  289. Note the syntactical structure of CreateControl(), (which is identical 
  290. to the syntactical structure of CreateReportControl()):
  291.  
  292.    Function CreateControl (FormName As String, 
  293.                            ControlType As Integer
  294.                            [,SectionNumber As Integer])
  295.  
  296. Use the SectionNumber parameter to indicate what section the control is
  297. to be placed into.  The section that is associated with the 
  298. SectionNumber is the same as the index representing a section in a
  299. Section property array.  
  300.  
  301.  
  302. WIZARDS PART 3
  303.  
  304. Summary:
  305.  
  306. This article discusses the Microsoft Access undocumented commands 
  307. DeleteControl, DeleteReportControl, and the undocumented function 
  308. CreateGroupLevel().  If you intend to write your own Forms and/or 
  309. Reports Wizard, you can use these functions to delete controls on a form 
  310. or report that is available in Design mode, and create groups on a 
  311. Report that is available in Design mode.
  312.  
  313. This article assumes that the reader has read and understands the
  314. Knowledge Base articles entitled, "Creating, Debugging, and Using an
  315. Access Library" (Q88175), "Wizards Part I - CreateForm(), CreateReport(), 
  316. Section Property" (Q?????), and "Wizards Part II - CreateControl(), 
  317. CreateReportControl()" (Q?????).  This article also assumes you are 
  318. familiar with Access Basic and with designing forms and reports.
  319.  
  320. This article applies to Microsoft Access Version 1.0.
  321.  
  322.  
  323. More Information:
  324.  
  325. DeleteControl and DeleteReportControl can be used to delete a control 
  326. that exists on a form/report in design mode.  Both of these functions 
  327. require a string value that represents the name of the form and a string 
  328. value that represents the name of the control.
  329.  
  330. DeleteControl and DeleteReportControl are commands - not functions.  
  331. They do not return a value.
  332.  
  333. The example below creates a form, then creates a button on the form,
  334. displays a message, then deletes the button on the form:
  335.  
  336.    Dim MyForm As Form, MyControl As Control
  337.    Set MyForm = CreateForm()
  338.    Set MyControl = CreateControl(MyForm.FormName, 104)
  339.    MsgBox "About to Delete " & MyControl.ControlName
  340.    DeleteControl MyForm.FormName, MyControl.ControlName
  341.  
  342. When you delete a control using DeleteControl or DeleteReportControl,
  343. there is no visual feedback that the control is gone if the form/report
  344. is not iconized.  The control still appears as if it were not deleted
  345. even though you could not click it into focus.  To make the deleted 
  346. control disappear in such a case, you would have to repaint the form
  347. design window by minimizing and restoring it.
  348.  
  349. If you have a report available in design mode, you can create groups 
  350. for it programmatically by using the CreateGroupLevel() function.  The
  351. syntactical structure of CreateGroupLevel() is shown below:
  352.  
  353.    Function CreateGroupLevel(ReportName As String,
  354.                              Expression As String,
  355.                              HasHeader As Integer,
  356.                              HasFooter As Integer)
  357.  
  358. ReportName is a string expression that indicates the name of the Report.
  359.  
  360. Expression is a string expression that represents the field name or
  361. calculated field on which the group will be based.
  362.  
  363. HasHeader and HasFooter indicate whether the group includes a group
  364. header or group footer, respectively.
  365.  
  366. When CreateGroupLevel() is executed, it adds a group at the innermost
  367. level.  For example, if one group already exists, CreateGroupLevel()
  368. will create a second group within the first group.  CreateGroupLevel()
  369. returns a number indicating which level it created, beginning with zero.  
  370. In the example just mentioned, CreateGroupLevel() would return 1 since
  371. it is the second group, and the first group was Group 0.
  372.